//
//  ZDWorkDetailController.m
//  特种车调度
//
//  Created by 陈宇 on 15/8/23.
//
//

#import "ZDWorkDetailController.h"
#import "ZDOrderDetailCell.h"
#import "ZDWorkDetailCell.h"
#import "CWStarRateView.h"
#import "BMAccountManager.h"
#import "ZDSelectPayController.h"
#import "ZDOrderDetailController.h"
#import "ZDWindController.h"

@interface ZDWorkDetailController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSTimer *timer;
@property(nonatomic, weak) UIView *topView;
@property(nonatomic, weak) ZDOrderDetailCell *detailCell;
@property(nonatomic, strong) NSArray *statusViews;
@property(nonatomic, weak) UITableView *tableView;
@property(nonatomic, weak) UIButton *signAllButton;

#pragma mark - 各种状态视图

#pragma mark 司机工作详情(工作中)(0)
@property(weak, nonatomic) IBOutlet UILabel *statusLabel;
@property(weak, nonatomic) IBOutlet UIButton *closeOrderButton;

- (IBAction)closeOrderAction:(id)sender;

#pragma mark 司机取消订单(1)

@property(weak, nonatomic) IBOutlet UILabel *reasonLabel;

#pragma mark 待评价(2)
@property(weak, nonatomic) IBOutlet UILabel *signPriceLabel;   //签收金额
@property(weak, nonatomic) IBOutlet UILabel *signCountLabel;   //签收方量
@property(weak, nonatomic) IBOutlet UIButton *discussButton;

@property(weak, nonatomic) IBOutlet UIButton *windButton;      //结算

@property(weak, nonatomic) IBOutlet UIView *discussContainerView;
@property(weak, nonatomic) IBOutlet CWStarRateView *ratingView;
@property(weak, nonatomic) IBOutlet BMTextView *textView;

- (IBAction)discussAction:(id)sender;

@end

@implementation ZDWorkDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"工作详情";
    self.view.backgroundColor = BMColor(245, 245, 245, 1);
    
    [self configuraion];
    
    [self getData];
}

- (void)getData {
    BMRequest *request = [BMRequest requestWithPath:@"getDispatcherOrderLogDetail.htm" contentKey:@"orderLog"];
    request.params = @{@"orderLogId" : @(_log.ID), @"ownerId" : @(_log.ownerId), @"orderId" : @(_order.ID)};
    [self showHudWithhint:kDefaultMessage];
    [OrderLog postWithRequest:request finish:^(BMResponse *response, NSError *error) {
        [self hideHud];
        if (response.status == kResultOK) {
            OrderLog *log = response.result;
            log.driver = _log.driver;
            log.licensePlate = _log.licensePlate;
            log.licensePlateNum = _log.licensePlateNum;
            log.icon = _log.icon;
            log.phone = _log.phone;
            log.style1 = _log.style1;
            log.styleName = _log.styleName;
            log.averageScore = _log.averageScore;
            _log = log;
            
            [self updateInfo];
            
            NSDictionary *sumService = response.rawResult[@"sumService"];
            if (sumService && ![sumService isKindOfClass:[NSNull class]]) {
                [self setupDiscussWithInfo:sumService];
            }
            NSDictionary *feedback = response.rawResult[@"feedback"];
            if (feedback && ![feedback isKindOfClass:[NSNull class]]) {
                [self setupFeedBackWithInfo:feedback];
            }
        } else {
            [self showHint:@"获取工作详情失败!"];
        }
    }];
}

- (NSTimer *)timer
{
    if (!_timer) {
        _timer = [NSTimer timerWithTimeInterval:60 target:self selector:@selector(fireRrfresh) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];
    }
    return _timer;
}

- (void)fireRrfresh
{
    [self getData];
    [self showHint:@"refresh"];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //    [self.timer setFireDate:[NSDate dateWithTimeIntervalSinceNow:60]];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //    self.timer.fireDate = [NSDate distantFuture];
}

- (void)updateInfo {
    ZDOwnerStatus status = _log.statusId;
    
    switch (status) {
        case ZDOwnerStatusRush:
        case ZDOwnerStatusRushSuccess:
        case ZDOwnerStatusGP:
        case ZDOwnerStatusDZ:
            [self setupWithWorkStatusView:self.statusViews[0]];
            self.statusLabel.text = @"暂未开始服务";
            break;
        case ZDOwnerStatusServiceLog:
            [self setupWithWorkStatusView:self.statusViews[0]];
            self.statusLabel.text = @"暂无待确认的服务";
            break;
        case ZDOwnerStatusWaitSign:
        case ZDOwnerStatusWaitWind:
            [self setupWithWaitSign];
            break;
        case ZDOwnerStatusEnded:
            [self setupDiscuss];
            break;
        case ZDOwnerStatusCommented:
            [self setupDiscussEnd];
            break;
        case ZDOwnerStatusCancel:
        case ZDOwnerStatusCancel1:
        case ZDOwnerStatusCancel2:
            [self setupWithWorkStatusView:self.statusViews[1]];
            if (_log.reason) {
                self.reasonLabel.text = _log.reason;
            } else {
                self.reasonLabel.text = _log.otherReason;
            }
            break;
        default:
            break;
    }
    
    if (_log.statusId == 2 || _log.statusId == 3 || _log.statusId == 4 || _log.statusId == 6) {
        self.closeOrderButton.hidden = NO;
    } else {
        self.closeOrderButton.hidden = YES;
    }
    
    
    _detailCell.log = _log;
    
    _detailCell.workStatusLabel.text = [_detailCell.log getMsg];
    if (_order.status == ZDOrderStatusDoing || _order.status == ZDOrderStatusEnded) {
        _detailCell.workStatusLabel.hidden = NO;
        if (_detailCell.log.damage <= 0)
            _detailCell.workStatusLabel.text = [_detailCell.log getMsg];
        else
            _detailCell.workStatusLabel.text = [NSString stringWithFormat:@"%@(获赔%.1f元)", [_detailCell.log getMsg], _detailCell.log.damage];
    } else if (_order.status == ZDOrderStatusCancel) {
        if (_detailCell.log.statusId == 5 || _detailCell.log.statusId == 11 || _detailCell.log.statusId == 12) {
            //            _detailCell.workStatusLabel.hidden = YES;
        } else {
            _detailCell.workStatusLabel.hidden = NO;
            _detailCell.workStatusLabel.text = [NSString stringWithFormat:@"获赔%.1f元", _detailCell.log.damage];
        }
    } else {
        //        _detailCell.workStatusLabel.hidden = YES;
    }
}

- (void)configuraion {
    ZDOrderDetailCell *cell = [[NSBundle mainBundle] loadNibNamed:@"ZDOrderDetailCell" owner:nil options:nil].firstObject;
    cell.log = _log;
    
    cell.workStatusLabel.text = [cell.log getMsg];
    if (_order.status == ZDOrderStatusDoing || _order.status == ZDOrderStatusEnded) {
        cell.workStatusLabel.hidden = NO;
        if (cell.log.damage <= 0)
            cell.workStatusLabel.text = [cell.log getMsg];
        else
            cell.workStatusLabel.text = [NSString stringWithFormat:@"%@(获赔%.1f元)", [cell.log getMsg], cell.log.damage];
    } else if (_order.status == ZDOrderStatusCancel) {
        if (cell.log.statusId == 5 || cell.log.statusId == 11 || cell.log.statusId == 12) {
            //            cell.workStatusLabel.hidden = YES;
        } else {
            cell.workStatusLabel.hidden = NO;
            cell.workStatusLabel.text = [NSString stringWithFormat:@"获赔%.1f元", cell.log.damage];
        }
    } else {
        //        cell.workStatusLabel.hidden = YES;
    }
    
    UIView *containerView = [[UIView alloc] init];
    containerView.backgroundColor = [UIColor whiteColor];
    containerView.layer.shadowColor = [UIColor grayColor].CGColor;
    containerView.layer.shadowOpacity = 0.2;
    containerView.layer.shadowOffset = CGSizeMake(0, 2);
    [containerView addSubview:cell];
    [self.view addSubview:containerView];
    self.topView = containerView;
    self.detailCell = cell;
    [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(65.f);
        make.left.mas_equalTo(self.view).offset(10);
        make.right.mas_equalTo(self.view).offset(-10);
        make.top.mas_equalTo(self.view).offset(74);
    }];
    [cell mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(containerView).offset(0);
        make.height.mas_equalTo(57);
    }];
}

- (void)setupDiscussEnd {
    [self setupWithWorkStatusView:self.statusViews[2]];
    self.ratingView.userInteractionEnabled = NO;
    self.textView.editable = NO;
    self.textView.placeHolder = nil;
    self.textView.backgroundColor = [UIColor clearColor];
    self.discussButton.hidden = YES;
}

- (void)setupDiscussWithInfo:(NSDictionary *)info {
    self.signPriceLabel.text = [NSString stringWithFormat:@"￥%@", info[@"realSumPrice"]];
    self.signCountLabel.text = [NSString stringWithFormat:@"%.1f方", [info[@"volume"] doubleValue]];
}

- (void)setupFeedBackWithInfo:(NSDictionary *)info {
    self.ratingView.scorePercent = [info[@"score"] doubleValue] / 10;
    self.textView.text = info[@"content"];
}

/**
 *  待评价
 */
- (void)setupDiscuss {
    [self setupWithWorkStatusView:self.statusViews[2]];
    self.discussContainerView.hidden = NO;
}

- (void)setupWithWorkStatusView:(UIView *)statusView {
    [self.view addSubview:statusView];
    [statusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view).offset(10);
        make.right.mas_equalTo(self.view).offset(-10);
        make.top.mas_equalTo(self.topView.mas_bottom);
        make.bottom.mas_equalTo(self.view).offset(-10);
    }];
}

/**
 *  工作中服务待签收
 */
- (void)setupWithWaitSign {
    if (_log.serviceLogs.count) {
        
        __block BOOL showOneSign = NO;  //一键签收
        __block BOOL showOneWind = NO;  //一键结算
        
        [_log.serviceLogs enumerateObjectsUsingBlock:^(ServiceLog *obj, NSUInteger idx, BOOL *stop) {
            if (obj.status == 0) {
                showOneSign = YES;
                *stop = YES;
            }
        }];
        
        if (!showOneSign) {
            [_log.serviceLogs enumerateObjectsUsingBlock:^(ServiceLog *obj, NSUInteger idx, BOOL *stop) {
                if (obj.status == 1) {
                    showOneWind = YES;
                    *stop = YES;
                }
            }];
        }
        
        UITableView *tableView = [[UITableView alloc] init];
        tableView.backgroundColor = [UIColor clearColor];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.rowHeight = UITableViewAutomaticDimension;
        tableView.estimatedRowHeight = 250.0; // 设置为一个接近“平均”行高的值
        [tableView registerNib:[UINib nibWithNibName:@"ZDWorkDetailCell" bundle:nil] forCellReuseIdentifier:reuseIdentifier];
        [self.view addSubview:tableView];
        self.tableView = tableView;
        
        if (showOneSign) {
            UIButton *signAllButton = [[UIButton alloc] init];
            [signAllButton setTitle:@"一键签收" forState:UIControlStateNormal];
            [signAllButton setTitle:@"确认" forState:UIControlStateSelected];
            [signAllButton setBackgroundImage:[UIImage imageNamed:@"bg_sure"] forState:UIControlStateNormal];
            signAllButton.titleLabel.font = [UIFont systemFontOfSize:14.f];
            [signAllButton addTarget:self action:@selector(signAllAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:signAllButton];
            self.signAllButton = signAllButton;
            [signAllButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(self.view).offset(-18);
                make.centerX.mas_equalTo(self.view);
            }];
            
            [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.view).offset(10);
                make.right.mas_equalTo(self.view).offset(-10);
                make.top.mas_equalTo(self.topView.mas_bottom).offset(10);
                make.bottom.mas_equalTo(signAllButton.mas_top);
            }];
        } else if (showOneWind) {
            UIButton *signAllButton = [[UIButton alloc] init];
            [signAllButton setTitle:@"一键结算" forState:UIControlStateNormal];
            [signAllButton setTitle:@"确认" forState:UIControlStateSelected];
            [signAllButton setBackgroundImage:[UIImage imageNamed:@"bg_sure"] forState:UIControlStateNormal];
            signAllButton.titleLabel.font = [UIFont systemFontOfSize:14.f];
            [signAllButton addTarget:self action:@selector(windAllAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:signAllButton];
            self.signAllButton = signAllButton;
            [signAllButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(self.view).offset(-18);
                make.centerX.mas_equalTo(self.view);
            }];
            
            [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.view).offset(10);
                make.right.mas_equalTo(self.view).offset(-10);
                make.top.mas_equalTo(self.topView.mas_bottom).offset(10);
                make.bottom.mas_equalTo(signAllButton.mas_top);
            }];
        } else {
            [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.view).offset(10);
                make.right.mas_equalTo(self.view).offset(-10);
                make.top.mas_equalTo(self.topView.mas_bottom).offset(10);
                make.bottom.mas_equalTo(self.view);
            }];
        }
    } else {
        [self setupWithWorkStatusView:self.statusViews[0]];
        self.statusLabel.text = @"暂无待确认的服务";
    }
}

- (NSArray *)statusViews {
    if (!_statusViews) {
        _statusViews = [[NSBundle mainBundle] loadNibNamed:@"WorkStatusView" owner:self options:nil];
        self.ratingView.scorePercent = 0;
        self.ratingView.hasAnimation = YES;
        self.ratingView.allowIncompleteStar = YES;
        self.textView.placeHolder = @"请输入您对车主的评价，200字以内。";
    }
    return _statusViews;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _log.serviceLogs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZDWorkDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    ServiceLog *log = _log.serviceLogs[indexPath.row];
    cell.serviceLog = log;
    weakSelf(self);
    cell.signOP = ^(NSUInteger status) {
        if (status == 0) {
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:@"是否确定签收该服务!" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
            [alertVC addAction:cancleAction];
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                [self signTask:@[_log.serviceLogs[indexPath.row]]];
            }];
            [alertVC addAction:okAction];
            //            [cancleAction setValue:kGlobalColor forKeyPath:@"titleTextColor"];
            //            [okAction setValue:kGlobalColor forKeyPath:@"titleTextColor"];
            [weakSelf presentViewController:alertVC animated:YES completion:nil];
        } else {
            //            ZDWindController *windVC = [ZDWindController new];
            //            windVC.order = _order;
            //            windVC.log = _log;
            //            windVC.indexPath = indexPath;
            //            [self showViewController:windVC sender:nil];
            NSString *msg = [NSString stringWithFormat:@"结算金额:￥%.1f\n方量:%.1f\n确定签收?\n", log.realsumPrice, log.volume];
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:msg preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
            [alertVC addAction:cancleAction];
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                [self windTask:@[log]];
            }];
            [alertVC addAction:okAction];
            //            [cancleAction setValue:kGlobalColor forKeyPath:@"titleTextColor"];
            //            [okAction setValue:kGlobalColor forKeyPath:@"titleTextColor"];
            [weakSelf presentViewController:alertVC animated:YES completion:nil];
        }
    };
    cell.agreeSign = ^{
        log.agreeSignAll = !log.agreeSignAll;
        [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    };
    return cell;
}

/**
 *  结算一组服务
 *
 */
- (void)windTask:(NSArray *)logs {
    NSMutableString *ids = [NSMutableString string];
    
    for (ServiceLog *log in logs) {
        [ids appendFormat:@"%ld,", log.ID];
    }
    
    BMRequest *request = [BMRequest requestWithPath:@"settlementServiceLogs.htm"];
    request.params = @{@"serviceId" : [ids substringToIndex:ids.length - 1], @"disId" : [BMAccountManager sharedInstance].user.disId, @"ownerId" : @(_log.ownerId), @"truckId" : @(_log.truckId)};
    [self showHudWithhint:kDefaultMessage];
    [[BMHttpTool sharedInstance] postWith:request finish:^(BMResponse *response, NSError *error) {
        [self hideHud];
        if (response.status == kResultOK) {
            [self showHint:@"结算成功"];
            for (ServiceLog *log in logs) {
                log.status = 2;
                log.selected = NO;
            }
            [self.tableView removeFromSuperview];
            [self.signAllButton removeFromSuperview];
            [self setupWithWaitSign];
        } else if (response.status == 8) {
            ZDSelectPayController *payVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"selectPayVC"];
            [self showViewController:payVC sender:nil];
            [self showHint:response.msg];
        } else {
            [self showHint:response.msg];
        }
    }];
}

/**
 *  签收一组服务
 *
 */
- (void)signTask:(NSArray *)serviceLogs {
    NSMutableString *ids = [NSMutableString string];
    
    for (ServiceLog *log in serviceLogs) {
        [ids appendFormat:@"%ld,", log.ID];
    }
    
    BMRequest *request = [BMRequest requestWithPath:@"signAgreeServiceLogs.htm"];
    request.params = @{@"serviceId" : [ids substringToIndex:ids.length - 1], @"orderId" : @(_order.ID), @"ownerId" : @(_log.ownerId)};
    [self showHudWithhint:kDefaultMessage];
    [[BMHttpTool sharedInstance] postWith:request finish:^(BMResponse *response, NSError *error) {
        [self hideHud];
        if (response.status == kResultOK) {
            for (ServiceLog *log in serviceLogs) {
                log.selected = NO;
                log.status = 1;
            }
            //            if (self.signAllButton.selected) {
            [self.tableView removeFromSuperview];
            [self.signAllButton removeFromSuperview];
            [self setupWithWaitSign];
            //            } else {
            //                [self.tableView reloadData];
            //            }
        } else {
            [self showHint:@"签收失败!"];
        }
    }];
}

/**
 *  一键签收
 */
- (void)signAllAction:(UIButton *)sender {
    NSMutableArray *signLogs = [NSMutableArray array];
    for (ServiceLog *log in _log.serviceLogs) {
        if (log.status == 0) {
            [signLogs addObject:log];
        }
    }
    if (signLogs.count == 0) {
        [self showHint:@"暂无可签收的服务记录"];
        return;
    }
    
    if (sender.selected) {
        NSMutableArray *agreeLogs = [NSMutableArray array];
        [signLogs enumerateObjectsUsingBlock:^(ServiceLog *obj, NSUInteger idx, BOOL *stop) {
            if (obj.agreeSignAll) {
                [agreeLogs addObject:obj];
            }
        }];
        if (agreeLogs.count) {
            [self signTask:agreeLogs];
        } else {
            [self showHint:@"请选择至少一条记录"];
        }
    } else {
        for (ServiceLog *log in signLogs) {
            log.selected = YES;
        }
        [self.tableView reloadData];
        sender.selected = YES;
    }
}

- (void)windAllAction:(UIButton *)sender
{
    NSMutableArray *signLogs = [NSMutableArray array];
    for (ServiceLog *log in _log.serviceLogs) {
        if (log.status == 1) {
            [signLogs addObject:log];
        }
    }
    if (signLogs.count == 0) {
        [self showHint:@"暂无待结算的服务记录"];
        return;
    }
    
    if (sender.selected) {
        NSMutableArray *agreeLogs = [NSMutableArray array];
        [signLogs enumerateObjectsUsingBlock:^(ServiceLog *obj, NSUInteger idx, BOOL *stop) {
            if (obj.agreeSignAll) {
                [agreeLogs addObject:obj];
            }
        }];
        if (agreeLogs.count) {
            //            [self windTask:agreeLogs];
            ZDWindController *windVC = [ZDWindController new];
            windVC.order = _order;
            windVC.log = _log;
            windVC.logs = agreeLogs;
            [self showViewController:windVC sender:nil];
        } else {
            [self showHint:@"请选择至少一条记录"];
        }
    } else {
        for (ServiceLog *log in signLogs) {
            log.selected = YES;
        }
        [self.tableView reloadData];
        sender.selected = YES;
    }
}

- (void)signTaskGO:(NSArray *)logs
{
    NSMutableString *ids = [NSMutableString string];
    
    for (ServiceLog *log in logs) {
        [ids appendFormat:@"%ld,", log.ID];
    }
    
    BMRequest *request = [BMRequest requestWithPath:@"signAgreeServiceLogs.htm"];
    request.params = @{@"serviceId" : [ids substringToIndex:ids.length - 1], @"orderId" : @(_order.ID), @"ownerId" : @(_log.ownerId)};
    [self showHudWithhint:kDefaultMessage];
    [[BMHttpTool sharedInstance] postWith:request finish:^(BMResponse *response, NSError *error) {
        [self hideHud];
        if (response.status == kResultOK) {
            [self.signAllButton removeFromSuperview];
            [self.tableView removeFromSuperview];
            [self setupWithWaitSign];
            
            ZDWindController *windVC = [ZDWindController new];
            windVC.order = _order;
            windVC.log = _log;
            windVC.logs = logs;
            [self showViewController:windVC sender:nil];
        } else {
            [self showHint:@"签收失败!"];
        }
    }];
}

/**
 *  调度员关闭车主的订单，
 *
 */
- (IBAction)closeOrderAction:(id)sender {
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:@"是否确定关闭该车主的订单?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertVC addAction:cancleAction];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        BMRequest *request = [BMRequest requestWithPath:@"agreeOwnersCancleOrderByDispatcher.htm"];
        request.params = @{@"orderId" : @(_order.ID), @"ownerId" : @(_log.ownerId), @"action" : @3};
        [[BMHttpTool sharedInstance] postWith:request finish:^(BMResponse *response, NSError *error) {
            if (response.status == kResultOK) {
                NSArray *childVCs = self.navigationController.childViewControllers;
                ZDOrderDetailController *detailVC = childVCs[childVCs.count - 2];
                [detailVC refreshOrder];
                [self.navigationController popViewControllerAnimated:YES];
            } else {
                [self showHint:@"订单关闭失败"];
            }
        }];
    }];
    [alertVC addAction:okAction];
    [self presentViewController:alertVC animated:YES completion:nil];
}

- (IBAction)discussAction:(id)sender {
    BMRequest *request = [BMRequest requestWithPath:@"addFeedbackToOwner.htm"];
    request.params = @{@"dispacherId" : @([BMAccountManager sharedInstance].user.ID), @"orderId" : @(_order.ID), @"ownerId" : @(_log.ownerId), @"ranking" : @(_ratingView.scorePercent * 10), @"content" : [BMUtils isEmptyString:_textView.text] ? @" " : _textView.text, @"orderLogId" : @(_log.ID)};
    [self showHudWithhint:kDefaultMessage];
    [[BMHttpTool sharedInstance] postWith:request finish:^(BMResponse *response, NSError *error) {
        [self hideHud];
        if (response.status == kResultOK) {
            [self showHint:@"评价成功!"];
            [self.navigationController popViewControllerAnimated:YES];
        } else {
            [self showHint:@"评价失败!"];
        }
    }];
}

- (void)updateData
{
    [self.tableView removeFromSuperview];
    [self.signAllButton removeFromSuperview];
    [self setupWithWaitSign];
}

@end
